{extend name="public:base" /}{block name="css"}
<link href="/static/laydate/theme/default/laydate.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/css/select2.min.css" rel="stylesheet"/>{/block}{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <div class="row search-form">
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <input placeholder="请选择开始日期" type="text" name="start_time" value="{:input('start_time')}" class="form-control form-control-lg screen-date" readonly>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <input placeholder="请选择结束日期" type="text" name="end_time" value="{:input('end_time')}" class="form-control form-control-lg screen-date" readonly>
                            </div>
                        </div>

                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <select name="region_id" id="region_id" class="form-control form-control-lg">
                                    <option value="0">请选择区域</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <select name="shop_id" id="shop_id" class="form-control form-control-lg">
                                    <option value="0">请选择门店</option>
                                </select>
                            </div>
                        </div>

                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <style>
                                    .select2-container--default .select2-selection--single {
                                        background-color: #fff;
                                        border: 1px solid #e5e6e7;
                                        border-radius: 4px;
                                    }
                                </style>
                                <select name="user_id" class="form-control form-control-lg" id="select2">
                                    <option value="0">请选择会员</option>
                                    {volist name="user_list" id="vo"}
                                    <option value="{$vo.id}" {$vo.id== input(
                                    'user_id') ? 'selected' : ''}>{$vo.username} / {$vo.mobile}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>

                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <select name="status_code" class="form-control form-control-lg">
                                    <option value="">请选择订单状态</option>
                                    <option value="1" {:input(
                                    'status_code') == 1 ? 'selected' : ''}>未发货</option>
                                    <option value="2" {:input(
                                    'status_code') == 2 ? 'selected' : ''}>已发货</option>
                                    <option value="3" {:input(
                                    'status_code') == 3 ? 'selected' : ''}>已收货</option>
                                    <option value="4" {:input(
                                    'status_code') == 4 ? 'selected' : ''}>待核销</option>
                                    <option value="5" {:input(
                                    'status_code') == 5 ? 'selected' : ''}>已领取</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <button type="button" class="btn btn-primary btn-lg screen-btn">搜索</button>
                                <!--                                <button type="button" class="btn btn-primary btn-lg excel-btn">导出</button>-->
                            </div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>会员昵称</th>
                                <th>会员手机号</th>
                                <th>门店</th>
                                <th>领取方式</th>
                                <th>领取物品信息</th>
                                <th>收货地址</th>
                                <th>快递信息</th>
                                <th>状态</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo"}
                            <tr>
                                <td>{$vo.id}</td>
                                <td>{$vo.username}</td>
                                <td>{$vo.mobile}</td>
                                <td>{$vo.shop_name}</td>
                                <td>{$vo.send_type == 1 ? '自提' : '邮寄'}</td>
                                <td>{$vo.goods_name}（{$vo.count}）</td>
                                <td>{$vo.get_province}{$vo.get_city}{$vo.get_area}{$vo.get_address}</td>
                                <td>{$vo.shipper_name} / {$vo.shipper_code}</td>
                                <td>{$vo.status_text}</td>
                                <td>{:timeFormat($vo.create_time)}</td>
                                <td class="project-actions">
                                    {if $vo.send_type == 2 && $vo.shipper_status == 0}
                                    <a href="javascript: void(0)" onclick="addModelOpen({$vo.id})" class="btn btn-white btn-sm">
                                        <i class="iconfont icon-caozuo_disu"></i> 发货
                                    </a>
                                    {/if}
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                        {if !empty($list)}{$list->render()}{/if}
                    </div>

                </div>
            </div>
        </div>

    </div>
</div>

<div class="modal inmodal" id="myModal5" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content animated flipInY">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" onclick="modelClose()"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title">发货</h4>
            </div>
            <div class="modal-body">
                <select class="form-control shipper_id">
                    <option value="0">请选择物流公司</option>
                    {volist name='shipper_list' id="vo"}
                    <option value="{$vo.id}">{$vo.name}</option>
                    {/volist}
                </select>

                <input type="text" class="form-control shipper_code" placeholder="请输入快递单号" style="margin-top: 10px">

                <input type="hidden" class="id" value="">
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-white" onclick="modelClose()">关闭</button>
                <button type="button" class="btn btn-primary" onclick="confirmChange()">确认</button>
            </div>
        </div>
    </div>
</div>{/block}

{block name="js"}
<script src="/static/laydate/laydate.js"></script>

<script src="__STATIC__/jquery/jquery-3.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/js/select2.min.js"></script>
<script>
    laydate.render({
        elem: '.screen-date' //指定元素
    });

    $('#select2').select2()

    var id = 0;

    function getOrderInfo(order_id, pay_price) {
        id = order_id;
        $('#myModal3 .pay_price').val(pay_price);
    }

    function modelClose() {
        $('body').removeClass('modal-open');
        $('.modal-backdrop').remove();
        $('#myModal3').css('display', 'none').removeClass('show');
        id = 0;
    }

    $('#confirm').click(function () {
        var pay_price = $('.pay_price').val();

        var url = "/admin/manage/changePayPrice";
        $.post(url, {
            id, pay_price
        }, function (res) {
            layer.msg(res.msg)
            if (res.result == 1) {
                modelClose();
                window.location.reload();
            }
        }, 'json')
    })


    // 区域-门店 联动
    var region_list = `{:getRegionToShop()}` ? JSON.parse(`{:getRegionToShop()}`) : [];
    var region_id = `{:input('region_id')}` ? parseInt(`{:input('region_id')}`) : 0;
    var shop_id = `{:input('shop_id')}` ? parseInt(`{:input('shop_id')}`) : 0;

    if (region_list.length) {
        var option = `<option value="0">请选择区域</option>`;
        region_list.forEach(val => {
            var selected = region_id == val.id ? 'selected' : '';
            option += `<option value="${val.id}" ${selected}>${val.name}</option>`;
        })
        $('#region_id').html(option)
    }

    if (region_id) {
        var option = `<option value="0">请选择门店</option>`;
        for (var i = 0; i < region_list.length; i++) {
            if (region_list[i].id == region_id) {
                var shop_list = region_list[i].shop_list;
                if (shop_list.length) {
                    shop_list.forEach(val => {
                        var selected = val.id == shop_id ? 'selected' : '';
                        option += `<option value="${val.id}" ${selected}>${val.name}</option>`;
                    })
                }
                $('#shop_id').html(option);
                break;
            }
        }
        $('#shop_id').html(option);
    }

    $('#region_id').on('change', function () {
        var id = $(this).val();
        var option = `<option value="0">请选择门店</option>`;
        if (id > 0) {
            for (var i = 0; i < region_list.length; i++) {
                var region_id = region_list[i].id;
                if (id == region_id) {
                    var shop_list = region_list[i].shop_list;
                    if (shop_list.length) {
                        shop_list.forEach(val => {
                            option += `<option value="${val.id}">${val.name}</option>`;
                        })
                    }
                    $('#shop_id').html(option);
                    break;
                }
            }
        } else {
            $('#shop_id').html(option);
        }
    })

    function addModelOpen(id) {
        $('body').addClass('modal-open').append('<div class="modal-backdrop show"></div>');
        $('#myModal5').css('display', 'block').addClass('show');

        $('.id').val(id);
    }

    // 关闭 积分变更 弹框
    function modelClose() {
        $('body').removeClass('modal-open');
        $('.modal-backdrop').remove();
        $('#myModal5').css('display', 'none').removeClass('show');

        $('#myModal5 .shipper_id').val(0);
        $('#myModal5 .shipper_code').val('');
        $('#myModal5 .id').val('');
    }

    // 积分变更
    var clickCount = 0;

    function confirmChange() {
        var id = $('#myModal5 .id').val();
        var shipper_id = $('#myModal5 .shipper_id').val();
        var shipper_code = $('#myModal5 .shipper_code').val();
        if (clickCount == 0) {
            ++clickCount;
            $.post("{:url('sendShipper')}", {
                id: id,
                shipper_id: shipper_id,
                shipper_code: shipper_code,
            }, function (res) {
                if (res.result == 1) {
                    layer.msg(res.msg);
                    setTimeout(function () {
                        window.location.reload();
                    }, 500)
                } else {
                    clickCount = 0;
                    layer.msg(res.msg);
                }
            }, 'json')
        }
    }
</script>{/block}

